"""create events and many to one relationship

Revision ID: 4149f66b5194
Revises: 3d195160b2e3
Create Date: 2024-03-07 14:55:10.852676

"""

from typing import Sequence, Union

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "4149f66b5194"
down_revision: Union[str, None] = "3d195160b2e3"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "events",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(), nullable=False),
        sa.PrimaryKeyConstraint("id"),
    )
    with op.batch_alter_table("tickets") as batch_op:
        batch_op.add_column(
            sa.Column(
                "event_id", sa.Integer(), nullable=True
            )
        )
        batch_op.create_foreign_key(
            "fk_tickets_event_id_events",
            "events",
            ["event_id"],
            ["id"],
        )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("tickets") as batch_op:
        batch_op.drop_constraint(
            "fk_tickets_event_id_events",
            type_="foreignkey",
        )
        batch_op.drop_column("event_id")
    op.drop_table("events")
    # ### end Alembic commands ###
